package com.boot.dongli.ttl2;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author: lkz
 * @Title: TTLProTwoMsg
 * @Description: 消息生产 队列消息过期
 * @Date: 2023/10/16 14:14
 */
@Component
@Slf4j
public class TTLProTwoMsg {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendMsg(){
        MessageProperties messageProperties=new MessageProperties();
        Message message= MessageBuilder.withBody("hello world".getBytes())
                .andProperties(messageProperties).build();
        rabbitTemplate.convertAndSend("ttl.two.exchange","info",message);
        log.info("消息发送完毕，发送时间为：{}",new Date());
    }

}
